<template>
  <div>
    <div class="dashboard-container">
      

      <div class="big-back-box">
        <div class="top" style="margin-bottom: 20px">查看账户信息</div>
        <!-- 卡片 -->
        <div style="width: 600px; margin: 0 auto">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="头像">
              <el-upload
                class="avatar-uploader"
                action="http://123.60.85.153:8080/lawServicePlatform/common/uploadFile"
                :headers="token"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img
                  v-if="form.headPortrait"
                  :src="form.headPortrait"
                  class="el-upload-list__item-thumbnail"
                  style="width: 100px; height: 100px"
                />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
            <!-- 用户ID -->
            <el-form-item label="用户ID">
              <el-input v-model="form.id" :disabled="true"></el-input>
            </el-form-item>
            <!-- 昵称（可修改） -->
            <el-form-item label="昵称">
              <el-input v-model="form.nickname" :disabled="false"></el-input>
            </el-form-item>
            <!-- 姓名 -->
            <el-form-item label="姓名">
              <el-input v-model="form.name" :disabled="false"></el-input>
            </el-form-item>
            <!-- 性别 -->
            <el-form-item label="性别">
              <el-input v-model="form.sex" :disabled="false"></el-input>
            </el-form-item>
            <!-- 出生日期 -->
            <el-form-item label="出生日期">
              <el-input v-model="form.birthDate" :disabled="false"></el-input>
            </el-form-item>
            <!-- 所在地址 -->
            <el-form-item label="所在地址">
              <el-input v-model="form.address" :disabled="false"></el-input>
            </el-form-item>
            <!-- 手机号 -->
            <el-form-item label="手机号">
              <el-input v-model="form.phone" :disabled="false"></el-input>
            </el-form-item>
            <!-- 邮箱 -->
            <el-form-item label="邮箱">
              <el-input v-model="form.email" :disabled="false"></el-input>
            </el-form-item>
            <!-- 身份证号码 -->
            <el-form-item label="身份证号码">
              <el-input v-model="form.idCard" :disabled="false"></el-input>
            </el-form-item>
            <!-- 状态 -->
            <el-form-item label="状态">
              <el-input v-model="form.state" :disabled="true"></el-input>
            </el-form-item>

            <!-- 按钮 -->
            <el-form-item>
              <el-button type="primary" @click="onSubmit">确定</el-button>
              <!-- <el-button>取消</el-button> -->
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  selectBuyerById,
  updatePersonalInformation
} from "@/api/customerAccount";
import { returnUserInformation } from "@/api/common";
import { getToken } from "@/utils/auth";
export default {
  mounted() {
    this.token["token"] = getToken();
    this.initBuyer();
  },
  data() {
    return {
      token: {},
      size: "",
      form: {}
    };
  },
  methods: {
    handleAvatarSuccess(res) {
      this.form.headPortrait = res.url;
      this.$message(res.message);
    },
    initBuyer() {
      //获取采买方的信息
      returnUserInformation().then(res => {
        this.form = res.data.user;
      });
    },
    onSubmit() {
      //修改之后
      updatePersonalInformation(this.form).then(resp => {
        let { data } = resp;
        if (data.result) {
          this.$message(data.message);
          this.initBuyer();
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
// 页头LOGO
.top {
  height: 50px;
  width: 1080px;
  margin-left: 45px;
  // background-color: lightgray;
  font-size: 30px;
  text-align: center;
  line-height: 50px;
}

// 大盒子
.big-back-box {
  width: 1080px;
  margin: 0 auto;
  // background-color: pink;
}

// 原框架自带
.dashboard {
  &-container {
    margin-top: 30px;
    // margin-left: 30px;
    // margin-right: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

// 页脚
.footer {
  height: 300px;
  background-color: blue;
}
.footer-back-box {
  width: 1080px;
  margin-left: 45px;
}
.footer-title {
  height: 30px;
  line-height: 40px;
  padding-left: 10px;
}
.footer-link-card {
  width: 200px;
  background-color: orange;
  margin-left: 10px;
}

// 模板-卡片
.text {
  font-size: 14px;
}
.item {
  padding: 18px 0;
}
.box-card {
  width: 480px;
}
</style>

<style scoped>
avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>